//:C05:CountedClass3.cpp
#include <iostream>
using namespace std;

template<class T> class Counted
{
    static int count;
    public:
        Counted(){++count;}
        Counted(const Counted<T>&){++count;}
        ~Counted(){--count;}
        static int getCount(){return count;}
};

template<class T> int Counted<T>::count = 0;
// Curious class definitions
class CountedClass : public Counted<CountedClass>{};
class CountedClass2 : public Counted<CountedClass2>{};

int main(void)
{
    CountedClass a;
    cout << CountedClass::getCount() << endl;    // 1
    CountedClass b;
    cout << CountedClass::getCount() << endl;    // 2
    CountedClass2 c;
    cout << CountedClass2::getCount() << endl;    // 1 (!)
}

